﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#endregion

namespace TheSpirit
{
    public class Tile
    {
        #region Declaration

        public enum TileState
        {
            Empty,
            Road,
            Block,
            Character,
            Tower,
            Enemy,
            Destination
        }
        public TileState tileState = TileState.Empty;

        private Rectangle worldLocation;
        private Rectangle localLocation;
        private Point tileLocation;
        private static Texture2D tileTexture;
        private bool inScreen = false;
        private bool destination = false;
        private bool isSelectCharacter = false;
        private Tile parent;

        private int f;
        private int g;

        #endregion


        #region Property

        //현재 화면의 안에 있는지 나타냄
        public bool Destination
        {
            set { destination = value; }
            get { return destination; }
        }
        public bool InScreen
        {
            set { inScreen = value; }
            get { return inScreen; }
        }
        public bool IsSelectCharacter
        {
            set { isSelectCharacter = value; }
            get { return isSelectCharacter; }
        }
        public int F
        {
            set { f = value; }
            get { return f; }
        }
        public int G
        {
            set { g = value; }
            get { return g; }
        }
        public Point TileLocation
        {
            set { tileLocation = value; }
            get { return tileLocation; }
        }
        public Rectangle WorldLocation
        {
            get { return worldLocation; }
        }
        public Rectangle LocalLocation
        {
            get { return localLocation; }
        }
        public Tile Parent
        {
            set { parent = value; }
            get { return parent; }
        }

        #endregion


        #region Initialize

        public Tile(int x, int y, int width, int height)
        {
            worldLocation.X = x;
            worldLocation.Y = y;
            worldLocation.Width = width;
            worldLocation.Height = height;
        }

        public static void LoadContent(ContentManager content)
        {
            tileTexture = content.Load<Texture2D>("Tiles/normal");
        }

        #endregion


        #region Draw

        public void Draw(SpriteBatch spriteBatch)
        {
            //if(tileState != TileState.Block)
                spriteBatch.Draw(tileTexture, localLocation, Color.Black * 0.5f);

            //타일 색 구별 -> 디버깅용
            //if (tileState == TileState.Character)
            //    spriteBatch.Draw(tileTexture, localLocation, Color.Green * 0.5f);
            //else if(tileState == TileState.Enemy)
            //    spriteBatch.Draw(tileTexture, localLocation, Color.Red * 0.5f);
            //else if (tileState == TileState.Block)
            //    spriteBatch.Draw(tileTexture, localLocation, Color.Yellow * 0.5f);

            //좌표 출력 -> 디버깅용
            //Fonts.Draw(spriteBatch, Fonts.Segoe14, 
            //    "(" + tileLocation.X.ToString() + "," + tileLocation.Y.ToString() + ")", 
            //    new Vector2(localLocation.X, localLocation.Y), Color.Red);

            if (isSelectCharacter)
            {
                if (tileState == TileState.Character)
                    spriteBatch.Draw(tileTexture, localLocation, Color.LightGreen);
            }
        }

        #endregion


        #region Helper

        public void setLocalLocation(int x, int y, int width, int height)
        {
            localLocation.X = x;
            localLocation.Y = y;
            localLocation.Width = width;
            localLocation.Height = height;
        }

        #endregion
    }
}
